package com.rk.order.receiver;

import com.rabbitmq.client.Channel;
import com.rk.common.constant.MqConst;
import com.rk.common.exception.YyghException;
import com.rk.common.result.ResultCodeEnum;
import com.rk.hosp.vo.msm.MsmVo;
import com.rk.order.mapper.MsmVoMapper;
import com.rk.order.service.MsmVoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSendException;
import org.springframework.stereotype.Component;

/**
 * @author :Rk.
 * @date : 2022/12/8
 */
@Component
@Slf4j
@RabbitListener(queues = MqConst.QUEUE_DLX)
public class DlxRevier {

    @Autowired
    private MsmVoMapper msmVoService;

    @RabbitHandler
    public void process(MsmVo msmVo, Message message, Channel channel) throws Exception {

        log.error("========================死信队列===============================");
        log.error("未发出的邮件信息为:"+msmVo);
        try {
            //将发送失败的邮件进行存储
            msmVoService.saveitem(msmVo);
            //手动确认消费
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }catch (Exception e) {
            e.printStackTrace();
            log.error("死信队列处理失败!");
        }
    }
}
